import request from '../../../../../public/js/common/api/api.js';

const ScmSaleUrl = Utils.CurDomain.ScmSaleUrl;
const AccountUrl = Utils.CurDomain.AccountUrl;

const SysAuthUrl = Utils.CurDomain.SysAuthUrl;
const SysPlfUrl = Utils.CurDomain.SysPlfUrl;
const configuration = {
    contentType: 'application/json',
    dataType: 'json',
    async: true,
    dataFilter(data, type) {
        return data;
    }
}

/**
 * @file神农招聘API
 */
export default class SalesPlanAPI {
    // 根据JWT获取人员信息
    static getUserInfo() {
        return request.get(`${SysAuthUrl}/account/u`);
    }

    // 获取登录用户对应的职员信息
    static getLoginUserToStaff() {
        return request.get(`${AccountUrl}/accounts/eply`);
    }

    // 获取登录用户拥有组织
    static postUserOrgsList() {
        return request.get(`${AccountUrl}/accounts/orgs`);
    }

    // 获取销售组织列表信息
    static getOrgsListType() {
        return request.get(`${SysPlfUrl}/yyorgunits/by/q/sale`);
    }

    // 查询所有物料
    static getMaterial() {
        return request.get(`${Utils.CurDomain.MasterDataUrl}/yymaterials/q`);
    }

    // 查询销售计划详情
    static querySalesInfo(id) {
        return request.get(`${ScmSaleUrl}/saleplanbills/${id}`);
    }
    // 修改销售计划
    static ediSalesList(id, data) {
        return request.put(`${ScmSaleUrl}/saleplanbills/${id}`, data, true, configuration);
    }
    // 删除销售计划
    static delSalesList(id) {
        return request.delete(`${ScmSaleUrl}/saleplanbills/${id}`);
    }
    // 新增销售计划列表
    static addSalesList(data) {
        return request.post(`${ScmSaleUrl}/saleplanbills`, data, true, configuration);
    }
    // 销售计划列表
    static querySalesList(data) {
        return request.post(`${ScmSaleUrl}/saleplanbills/list`, data);
    }
    // 搜索销售计划列表
    static seachEmployees(data) {
        let { searchInfo, pageIndex, pageSize, Sort, BillStatus } = data;
        const searchInfoParam = Utils.IsNotNull(BillStatus) ? `&BillStatus=${BillStatus}` : '';

        return request.get(`${ScmSaleUrl}/saleplanbills?pageSize=${pageSize}&pageIndex=${pageIndex}&SearchInfo=${searchInfo}&Sort=${Sort}${searchInfoParam}`);
    }
    // 提交销售计划
    static submitSales(id) {
        return request.put(`${ScmSaleUrl}/saleplanbills/submit/${id}`);
    }
    // 反提交销售计划
    static unsubmitSales(id) {
        return request.put(`${ScmSaleUrl}/saleplanbills/unsubmit/${id}`);
    }
    // 审核计划
    static auditSales(id) {
        return request.put(`${ScmSaleUrl}/saleplanbills/audit/${id}`);
    }
    // 反审核销售计划
    static antiauditSales(id) {
        return request.put(`${ScmSaleUrl}/saleplanbills/antiaudit/${id}`);
    }
}